<script lang="ts" setup>
import { Fold } from '@element-plus/icons-vue'
import { Expand } from '@element-plus/icons-vue'
import { ref } from 'vue'
import headerInfo from './c-cpns/header-info.vue'
import headerCrumb from './c-cpns/header-crumbs.vue'
//内部自定义事件,用于向父组件main传递菜单折叠状态的变化。
const emit = defineEmits(['foldChange'])

const isFold = ref(false)
function handleMenuIconClick() {
  isFold.value = !isFold.value //点击更改isFold的值，从而实现折叠和展开菜单的效果。
  emit('foldChange', isFold.value) //触发自定义事件，将折叠状态传递给父组件。
}
</script>

<template>
  <div class="main-header">
    <div class="menu-icon" @click="handleMenuIconClick">
      <el-icon>
        <component :is="isFold ? 'Expand' : 'Fold'"></component>
        <!--使用动态组件更改图标状态-->
      </el-icon>
    </div>
    <div class="content">
      <div class="breadcrumb">
        <header-crumb />
      </div>
      <header-info></header-info>
    </div>
  </div>
</template>

<style lang="less" scoped>
.main-header {
  display: flex;
  align-items: center;
  flex: 1;
  height: 100%;

  .menu-icon {
    display: flex;
    align-items: center; /*垂直居中*/
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 18px;
  }
}
</style>
